﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class RoomClip : MonoBehaviour,IDragHandler, IEndDragHandler, IBeginDragHandler
{
    Vector2 originPos;
    Image mainImg;
    bool isChoose = false;

    public void OnBeginDrag(PointerEventData eventData)
    {
        originPos = this.transform.position;
        mainImg.raycastTarget = false;
    }

    public void OnDrag(PointerEventData eventData)
    {
        if (isChoose == false)
        {
            this.transform.position = Input.mousePosition;
        }
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        GameObject go = eventData.pointerEnter;
        if (go != null && go.CompareTag("gap"))
        {
            this.transform.SetParent(go.transform);
            isChoose = true;
        }
        else
        {
            this.transform.position = originPos;
            mainImg.raycastTarget = true;
        }
    }

    void Start()
    {
        mainImg = this.GetComponent<Image>();
    }
}
